package com.tanhua.dubbo.api.db;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tanhua.dubbo.api.mapper.SoulQuestionMapper;
import com.tanhua.model.db.UserQuestion;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author zs
 * @version 1.8
 */
@DubboService
public class SoulQuestionApiImpl implements SoulQuestionApi {

    @Autowired
    private SoulQuestionMapper soulQuestionMapper;


    /**
     * 根据问题Id查询类型
     *
     * @param questionId
     * @return
     */
    @Override
    public String findTypeByQuestionId(Integer questionId) {

        LambdaQueryWrapper<UserQuestion> lqw = new LambdaQueryWrapper<>();
        lqw.eq(questionId!=null, UserQuestion::getQuestionId,questionId);
        UserQuestion userQuestion = soulQuestionMapper.selectOne(lqw);
        String questionType = userQuestion.getQuestionType();
        return questionType;
    }

    /**
     * 通过问题Id 获取对应问卷类型
     *
     * @param questionId
     * @return
     */
    @Override
    public Long getQuestionnaireId(int questionId) {
        LambdaQueryWrapper<UserQuestion> lqw = new LambdaQueryWrapper<>();
        lqw.eq(questionId!=0, UserQuestion::getQuestionId,questionId);
        UserQuestion userQuestion = soulQuestionMapper.selectOne(lqw);
        Long questionnaireId = userQuestion.getQuestionnaireId();
        return questionnaireId;
    }
}
